package Request;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import servlet.RequestProcess;

//import Container.*;

public class RequestFactory {
    private Request request;
    
    //Register
    public RequestFactory(RequestType rt, String username, String password, 
                          String name, String tel, String addr, String email) {
        request = new RegisterRequest(username, password, name, tel, addr, email);
        request.setRequestType(rt);
    }

    //Login
    public RequestFactory(RequestType rt, String username, String password) {
        request = new LoginRequest(username, password);
        request.setRequestType(rt);
    }
    
    //Logout, View Centre, Get Category, Get Hot Sell
    public RequestFactory(RequestType rt) {
        switch (rt) {
            case LOGOUT:
                request = new LogoutRequest();
                break;
            case VIEWCENTRE:
                request = new ViewCentreRequest();
                break;
            case GETCATEGORY:
                request = new GetCategoryRequest();
                break;
            case HOTSELL:
            	request = new HotSellRequest();
            	break;
            default:    
        }
        if (request != null) {
            request.setRequestType(rt);
        }        
    }
    
    //Search
    public RequestFactory(RequestType rt, String keyword, int category, int min, int max, boolean isBo) {
        request = new SearchRequest(keyword, category, min, max, isBo);
        request.setRequestType(rt);
    }
    
    //Sell
    public RequestFactory(RequestType rt, String name, int category, String img, String description, 
                          int co, int bo, int duration) {
        request = new SellRequest(name, category, img, description, co, bo, duration);
        request.setRequestType(rt);
    }
    
    //Bid
    public RequestFactory(RequestType rt, int iid, int price) {
        request = new BidRequest(iid, price);
        request.setRequestType(rt);
    }
    
    //Comment
    public RequestFactory(RequestType rt, int iid, String comment) {
        request = new CommentRequest(iid, comment);
        request.setRequestType(rt);
    }
    
    //Buyout, Search Page, View Detail
    public RequestFactory(RequestType rt, int value) {
        switch (rt) {
            case BUYOUT:
                request = new BuyoutRequest(value);
                break;
            case SEARCHPAGE:
                request = new SearchPageRequest(value);
                break;
            case VIEWDETAIL:
                request = new ViewDetailRequest(value);
                break;
            default:    
        }
        if (request != null) {
            request.setRequestType(rt);
        }      
    }
    
    public void init(int uID, int sID, HttpServletRequest req, HttpServletResponse resp, RequestProcess rp, String nextPage) {
        request.init(uID, sID);
        request.setupResponse(rp, req, resp, nextPage);
    }
    
    public Request getRequest() {
        return request;
    }
}